﻿namespace DB2WORD.Logics
{
    public class HashStack<T>
    {
        private List<T> list = new List<T>();
        public int Count { get { return list.Count; } }
        public void Clear()
        {
            this.list.Clear();
        }
        public bool Contains(T item)
        {
            return list.Contains(item);
        }
        public T? Peek()
        {
            return this.list.LastOrDefault();
        }
        public T? Pop()
        {
            var last = this.Peek();
            if(last != null)
            {
                this.list.Remove(last);
            }
            return last;
        }
        public void Push(T item)
        {
            if(this.Contains(item))
            {
                this.list.Remove(item);
            }
            this.list.Add(item);
        }
    }
}
